#include "BrickKBoom.h"

BrickKBoom::BrickKBoom(IDirect3DTexture9* mtex, RECT rect, float px, float py, float vx, float vy, float time){
	mID		= 0;
	mInfo	= 0;
	mWidth	= 4.0f;
	mHeight = 4.0f;
	mCenter = D3DXVECTOR3(mWidth/2, mHeight/2, 0.0f);
	mSpritePos.x = 8;
	mSpritePos.y = 8;

	mNeedCollision = false;
	mTex = mtex;
	mRECT = rect;
	mPos.x = px;
	mPos.y = py;
	mVelocity.x = vx;
	mVelocity.y = vy;
	mTime = time;
	
	mIsXGravity = false;
	mIsYGravity = true;
	
	MAX_VELOCITYX = 300;
	MAX_VELOCITYY = 300;
}

void BrickKBoom::update(float dt){
	if(mNeedDispose) return;
	if(mTime>0.0f){
		mRotation += mVelocity.x*dt/10;
		if(mRotation > 2*D3DX_PI){
			mRotation = 0.0f;
		}
		mTime -=dt;
		if(mTime <=0.0f){
			mNeedDispose = true;
			mTime = true;
			return;
		}
		updateMoving(dt, dt, dt);
	}
}

void BrickKBoom::render(ID3DXSprite* mSprite){
	if(mNeedDispose) return;

	HR(gDevice->SetRenderState(D3DRS_ALPHATESTENABLE,true));
	D3DXMATRIX S;
	D3DXMatrixScaling(&S,0.25f,-0.25f,1.0f);
	D3DXMATRIX R;
	D3DXMatrixRotationZ(&R, mRotation);
	D3DXMATRIX T;
	D3DXMatrixTranslation(&T,mPos.x - gCamera->getPos().x, mPos.y - gCamera->getPos().y, 0);
	mSprite->SetTransform(&(S*R*T));
	mSprite->Draw(mTex,&mRECT,&mCenter,0,D3DCOLOR_XRGB(255, 255, 255));
	mSprite->Flush();
	HR(gDevice->SetRenderState(D3DRS_ALPHATESTENABLE,false));
}

void BrickKBoom::clear(){
	mTex = NULL;
}

